package com.xiaoyu.base.entity;

import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.annotation.NonNull;

import in.srain.cube.request.JsonData;

@Entity(tableName = "conversation")
public class ConversationEntity {

    public static final int STATUS_MASK = 0x000000FF;
    public static final int STATUS_MUTE = 1;
    public static final int STATUS_DELETE = 1 << 1;
    public static final int STATUS_BLACKED = 1 << 2;
    public static final int STATUS_BLACK = 1 << 3;

    @PrimaryKey
    @NonNull
    private String chatId;
    private String type;
    private String name;
    private String icon;
    private String toUid;
    private String toUserAccid;
    private String lastMessageId;
    private long lastUpdateTime;
    private long topWeight;
    private int unreadCount;
    private int status;
    private String ext;

    @NonNull
    public String getChatId() {
        return chatId;
    }

    public void setChatId(@NonNull String chatId) {
        this.chatId = chatId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getToUserAccid() {
        return toUserAccid;
    }

    public void setToUserAccid(String toUserAccid) {
        this.toUserAccid = toUserAccid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public int getUnreadCount() {
        return unreadCount;
    }

    public void setUnreadCount(int unreadCount) {
        this.unreadCount = unreadCount;
    }

    public String getLastMessageId() {
        return lastMessageId;
    }

    public void setLastMessageId(String lastMessageId) {
        this.lastMessageId = lastMessageId;
    }

    public String getToUid() {
        return toUid;
    }

    public void setToUid(String toUid) {
        this.toUid = toUid;
    }

    public long getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(long lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getExt() {
        return ext;
    }

    public JsonData getExtData() {
        return JsonData.create(ext);
    }

    public void setExt(String ext) {
        this.ext = ext;
    }

    public boolean isMute() {
        return hasStatus(STATUS_MUTE);
    }

    public boolean isDelete() {
        return hasStatus(STATUS_DELETE);
    }

    public boolean isBlack() {
        return hasStatus(STATUS_BLACK);
    }

    public boolean isBlacked() {
        return hasStatus(STATUS_BLACKED);
    }

    public boolean hasStatus(int flag) {
        return (status & flag) == flag;
    }

    public long getTopWeight() {
        return topWeight;
    }

    public void setTopWeight(long topWeight) {
        this.topWeight = topWeight;
    }

    @Override
    public String toString() {
        return "ConversationEntity{" +
                "chatId='" + chatId + '\'' +
                ", type='" + type + '\'' +
                ", name='" + name + '\'' +
                ", icon='" + icon + '\'' +
                ", toUid='" + toUid + '\'' +
                ", toUserAccid='" + toUserAccid + '\'' +
                ", lastMessageId='" + lastMessageId + '\'' +
                ", lastUpdateTime=" + lastUpdateTime +
                ", topWeight=" + topWeight +
                ", unreadCount=" + unreadCount +
                ", status=" + status +
                ", ext='" + ext + '\'' +
                '}';
    }
}
